﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;

using System.Threading;


public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            NewsListInit();
            WeiboListInit();
            if (eSYSU.Business.UserService.IsLogin())
            {
                Response.Redirect("Member/UserCenter.aspx");
            }

            string cookie = eSYSU.Common.LocalStorage.GetCookieValue("eSYSU_Cookie_Username","UserName");
            if (!string.Equals(cookie, "null"))
                tb_SignInName.Text = cookie;
        }
    }

    //最新新闻Repeater初始化
    protected void NewsListInit()
    {
        Repeater_LatestNews.DataSource = eSYSU.Business.NewsService.GetLatestComplexNews(8);
        Repeater_LatestNews.DataBind();
    }

    //最新微博Repeater初始化
    protected void WeiboListInit()
    {
        Repeater_LatestWeibo.DataSource = eSYSU.Weibo.SinaWeiboHandler.GetStatusesList(eSYSU.Weibo.SinaWeiboHandler.GetWeiboXML(1));
        Repeater_LatestWeibo.DataBind();
    }

    //登录按钮事件
    protected void login_submit_btn_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(tb_SignInName.Text.Trim()) && !string.IsNullOrEmpty(tb_PWD.Text.Trim()))
        {
            if (eSYSU.Business.UserService.UserLogin(tb_SignInName.Text,tb_PWD.Text))
            {
                if (cb_Remember.Checked == true) //保存登录信息
                {
                    eSYSU.Common.LocalStorage.SetCookie("eSYSU_Cookie_Username", "UserName", tb_SignInName.Text, 14);
                }
                //写入Session并跳转页面
                eSYSU.Business.UserService.SetUserLoginSession(tb_SignInName.Text, 30);
                Response.Redirect("Member/UserCenter.aspx");
                string sss = eSYSU.DAL.SqlHelper.ConnString;
            }
            else
            {
                Response.Write(eSYSU.Common.StringHelper.JsIsNull("登录错误，请重试。"));
            }
        }
        else
        {
            Response.Write(eSYSU.Common.StringHelper.JsIsNull("登录错误，请重试。"));
        }
    }

    //每10分钟刷新微博列表一次
    protected void Timer_Weibo_Tick(object sender, EventArgs e)
    {
        Timer_Weibo.Interval = 60000;
        WeiboListInit();
    }
}